package com.txsj.scan.widget.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;

import com.txsj.scan.R;

/**
 * @Created by WangChuangJun on 2018/11/30
 * @Describe
 */
public class InputNumberDialog extends Dialog {

    private Activity activity;
    private EditText et_count;
    private TextView tv_start;


    public InputNumberDialog(Activity activity) {
        super(activity, R.style.IncreasePriceDialog);
        super.setContentView(R.layout.dialog_input_number);
        this.activity = activity;
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        this.setCanceledOnTouchOutside(true);
        init();
    }

    public void initData(long current_number){
        et_count.setText(current_number+"");
        tv_start.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                long count = 0;
                if (!TextUtils.isEmpty(et_count.getText().toString().trim())){
                    count = Long.valueOf(et_count.getText().toString().trim());
                }
                if (null != listener)listener.onChange(count);
                dismiss();
            }
        });
    }

    private void init() {
        tv_start = (TextView) findViewById(R.id.tv_start);
        et_count = (EditText) findViewById(R.id.et_count);
    }

    private OnOkChangeListener listener;

    public void setListener(OnOkChangeListener listener) {
        this.listener = listener;
    }

    public interface OnOkChangeListener{
        void onChange(long count);
    }

}
